﻿using System;

namespace Toybox.NicoSharp.Utilities
{
	/// <summary>
	/// Time Utility
	/// </summary>
	public static class TimeUtility
	{

		private static readonly DateTime DATETIME_UNIXEPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

		/// <summary>
		/// DateTime を UnixTime に変換する
		/// </summary>
		/// <param name="time"></param>
		/// <returns></returns>
		public static int DateTimeToUnixTime(DateTime time)
		{
			return (int)time.ToUniversalTime().Subtract(DATETIME_UNIXEPOCH).TotalSeconds;
		}

		/// <summary>
		/// UnixTime を DateTime に変換する
		/// </summary>
		/// <param name="time"></param>
		/// <param name="kind"></param>
		/// <returns></returns>
		public static DateTime UnixTimeToDateTime(int time, DateTimeKind kind = DateTimeKind.Local)
		{
			return DATETIME_UNIXEPOCH.AddSeconds((double)time).ToLocalTime();
		}

	}
}
